import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { fileURLToPath, URL } from "node:url";
import Postcss from "postcss";
import postcssPxtorem from 'postcss-pxtorem';
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react(/*{
    babel: {
      plugins: ['@babel/plugin-transform-react-jsx'],
    },
  }*/)],
  css:{
    postcss: {
      plugins: [
        Postcss({
          plugins: [
            postcssPxtorem({
              rootValue: 75, // 已设计稿宽度375px为例 vant用的是375的设计稿
              propList: ['*'],
              exclude: (file)=>{
                // return  file.includes('node_modules')
                return  false
              }
            }),
          ]
        })
      ],
    }
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server:{
    proxy:{
      '/api':{
        target:'http://localhost:3000',
        changeOrigin:true,
        rewrite:path=>path.replace(/^\/api/,'')
      },
      '/image':{
        target:'http://localhost:3000',
        changeOrigin:true,
        rewrite:path=>path.replace(/^\/image/,'/image')
      }
    }
  }
})
